//
//  DBYPhotoViewController.m
//  MemoryTravel
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 fcx. All rights reserved.
//

#import "DBYPhotoViewController.h"

@interface DBYPhotoViewController ()
@property (nonatomic, retain) UIScrollView *photoScrollV;

@end

@implementation DBYPhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
#pragma mark - 创建ScrollView
    self.photoScrollV = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.photoScrollV.backgroundColor = [UIColor blackColor];
    // 按页滑动
    self.photoScrollV.pagingEnabled = YES;
    // 关闭边界反弹
    self.photoScrollV.bounces = NO;
    [self.view addSubview:self.photoScrollV];
    
    
    self.photoScrollV.contentSize = CGSizeMake(WIDTH * self.array.count, HEIGHT);
    
    for (int i = 0; i < self.array.count; i++) {
        
        // 设置图片的偏移量,点击哪张图片,从哪张开始滚送
        self.photoScrollV.contentOffset = CGPointMake(self.x * WIDTH, 0);
        
        UIImageView *photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * i + 10 * WID, 0, WIDTH - 10 * 2 * WID, HEIGHT)];
        DBYPhotoModel *photo = self.array[i];
        [photoImageView sd_setImageWithURL:[NSURL URLWithString:photo.image_url] placeholderImage:[UIImage imageNamed:@"loading.jpg"]];
        
        [self.photoScrollV addSubview:photoImageView];
        // 自动适应图片的大小
        photoImageView.contentMode = UIViewContentModeScaleAspectFit;
        
        
    }
    
#pragma mark - 创建轻拍
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.photoScrollV addGestureRecognizer:tap];
    
    
    
}

#pragma mark - 实现轻拍: 模态消失
- (void)tapAction:(UITapGestureRecognizer *)tap
{
    
    
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
    
}

    // Do any additional setup after loading the view.


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
